$.easing.custom = function (x, t, b, c, d) {
	var s = 1.70158;
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
};
$(function() {
	var root = $("#wizard").scrollable({easing: 'custom', speed: 700, circular: false});
	//var root = $("#wizard").scrollable();
    var api = root.scrollable(), drawer = $("#drawer");
    api.onBeforeSeek(function(event, i) {
		if (api.getIndex() < i) {
		    var page = root.find(".page").eq(api.getIndex()),
		    inputs = page.find('.error');
			//inputs = page.find(".required :input, select").removeClass("error"),
			empty = page.find('.required :input[value=""], select[value=""]');
		    if (empty.length || inputs.length) {
					drawer.slideDown();
			 	empty.addClass("error");
			 	return false;
		    }
			else { drawer.slideUp(); }
		}
	});
    api.onSeek(function(event, i) { 
    	var page = root.find(".page").eq(api.getIndex());
    		page.append($("#StoreCalc"));
			t = page.find(".cust");
		    u = page.find(".acct");
		    v = page.find(".cont");
		    w = page.find(".bill");
		    $("#StoreCalc").css("visibility", "hidden");
		    if (t.length>0) { 
		    	$("#status li").removeClass("active").eq(0).addClass("active");
		    	$("#StoreCalc").css("visibility", "visible");
		    }
		    else if (u.length>0) { $("#status li").removeClass("active").eq(1).addClass("active"); }
		    else if (v.length>0) { $("#status li").removeClass("active").eq(2).addClass("active"); }
		    else if (w.length>0) { $("#status li").removeClass("active").eq(3).addClass("active"); }
		    t = 0; u = 0; v = 0; w = 0;
	});             
	root.find("button.next").keydown(function(e) {
		if (e.keyCode == 9) {
			api.next();
			e.preventDefault();
		}
	});
	function CheckPage() {
		var page = root.find(".page").eq(api.getIndex());
		var e = page.find(".error");
		return e.length;
	}
	$('input[name="password1"]').blur(function() {
		var a = $(this).val();
		if (a == '' || a.length < 6 || a.length > 14) {
			drawer.slideDown();
			$(this).addClass("error");
		} 
		else {
			aa = $('input[name="password"]').val();
			ab = $('input[name="password1"]').val();
			if (aa == ab) {
				$(this).removeClass("error");
				if (CheckPage()==0) { drawer.slideUp(); }
			} else {
				$('input[name="password"]').addClass("error");
				$('input[name="password1"]').addClass("error");
			}
			aa = ''; ab = '';
		}
	});
	$('input[name="password"]').blur(function() {
		var a = $(this).val();
		if (a == '' || a.length < 6 || a.length > 14) {
			drawer.slideDown();
			$(this).addClass("error");
		} 
		else {
			aa = $('input[name="password"]').val();
			ab = $('input[name="password1"]').val();
			if (aa == ab) {
				$(this).removeClass("error");
				if (CheckPage()==0) { drawer.slideUp(); }
			} else {
				$('input[name="password1"]').addClass("error");
			}
			aa = ''; ab = '';
		}
	});
	$(':input[name="email"]').blur(function() {
		if (!isValidEmailAddress($(this).val())) {
			$(this).addClass("error"); drawer.slideDown();
		}
		else { $(this).removeClass("error"); if (CheckPage()==0) { drawer.slideUp(); } }
	});
	$(':input[name="username"]').blur(function() {
		if (isValidLength($(this).val(), 4)==0) {
			$(this).addClass("error"); drawer.slideDown();
		} else { $(this).removeClass("error"); if (CheckPage()==0) { drawer.slideUp(); } }
	});
	$('select').change(function() {
		var req = $(this).parent().get(0).className;
		var t = $(this).val();
		if (req == "required") {
			if (t == 0 || t == '') { $(this).addClass("error"); drawer.slideDown(); }
			else {
				$(this).removeClass("error");
				if (CheckPage()==0) {
				drawer.slideUp();
				}
			}
		}
	});
});
$(document).ready(function() {
	$('img').tooltip({
		position: "bottom center",
		effect: "fade"
	});
// function modalPopup(
//	align, 
//	top, 
//	width, 
//	padding, 
//	disableColor, 
//	disableOpacity, 
//	backgroundColor, 
//	borderColor, 
//	borderWeight, 
//	borderRadius, 
//	fadeOutTime, 
//	url, 
//	loadingImage)
	$("#but_yes").click(function() {
		alert("Go log in then!");
	});
	$("#dc").click(function() {
        modalPopup("center", 100, 920, 10, "#666666", 10, "#FFFFFE", "#000000", 2, 5, 200, "i1.html", "qmark.gif" );
     });
	$("#pr").click(function() {
        modalPopup( "center", 100, 920, 10, "#666666", 10, "#FFFFFE", "#000000", 2, 5, 200, "i2.html", "qmark.gif" );
     });
	$("#me").click(function() {
        modalPopup( "center", 100, 920, 10, "#666666", 10, "#FFFFFE", "#000000", 2, 5, 200, "i3.html", "qmark.gif" );
     });
	$("#di").click(function() {
        modalPopup( "center", 100, 920, 10, "#666666", 10, "#FFFFFE", "#000000", 2, 5, 200, "i4.html", "qmark.gif" );
     });
	$("#ba").click(function() {
        modalPopup( "center", 100, 920, 10, "#666666", 10, "#FFFFFE", "#000000", 2, 5, 200, "i5.html", "qmark.gif" );
     });

});
function isValidPass(str, str) {
	if (str === str) { return 0; }
	else { return 1; }
}
function isValidLength(str, len) {
  if (str.length >= len) { return 1; }
  else { return 0; }
}
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
    return pattern.test(emailAddress);
};